package cn.kgc.controller;



import cn.kgc.service.AppService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/app")
public class AppController {

    @Resource
    private AppService appService;


    /**
     * 跳转界面
     * @param aid
     * @param vid
     * @param modelMap
     * @return
     */
    @RequestMapping("/check")
    public String checkApp(@RequestParam Integer aid,
                           @RequestParam Integer vid,
                           ModelMap modelMap,
                           HttpSession session){
        //
        Map<String,Object> appInfo=new HashMap<>();
        Map<String,Object> appVersion=new HashMap<>();
        if (aid!=null||!"".equals(aid)){
            appInfo=appService.findCheckApp(aid,vid);
        }
        if (vid!=null || !"".equals(vid)){
            appVersion=appService.findCheckAppVid(vid);
        }
        if (appInfo!=null){
            //使用modelmap封装数据
            modelMap.addAttribute("aid",aid);
            modelMap.addAttribute("userSession",session.getAttribute("userSession"));
            modelMap.addAttribute("appInfo",appInfo);
            modelMap.addAttribute("appVersion",appVersion);
            //跳转到appcheck.jsp的界面
            return "backend/appcheck";
        }else {
            throw new  RuntimeException("审核异常");
        }
    }


    /**
     * 修改审核状态
     * @param id
     * @param status
     * @return
     */
    @RequestMapping("/checksave")
    public String checksave(@RequestParam Integer id,@RequestParam Integer status){
        int i=0;
        if (id!=null||!"".equals(id)||status!=null||!"".equals(status)){
            i=appService.updataApp(id,status);
        }
        if (i>0){
            return "redirect:/manager1/applist";
        }else {
            throw new RuntimeException("修改异常");
        }
    }



}
